package com.cci.kangdao.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cci.kangdao.dto.BaseResponse;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.cci.kangdao.service.NoticeService;
import com.cci.kangdao.utilTool.ParameterTool;

/**
 * 
 * 消息推送接口
 * @author Eric
 *
 */
@Controller
public class NoticeRest {

	@Autowired
	private NoticeService noticeService;
	
	private final static Logger log = Logger.getLogger(NoticeRest.class);
	
	/**
	 * 绑定用户和clientId
	 * @param cId 个推clientId
	 * @param userName 用户名
	 * @return
	 */
	@RequestMapping(value="/bindClientId.aspx")
	public ModelAndView bindClientId(HttpServletRequest request,
			HttpServletResponse response) {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return noticeService.bindClientId(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}
	
	/**
	 * 解绑用户和clientId
	 * @param userName 用户名
	 * @return
	 */
	@RequestMapping(value="/unbindClientId.aspx")
	public ModelAndView unblindClientId(HttpServletRequest request,
			HttpServletResponse response) {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return noticeService.unbindClientId(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}
	
	/**
	 * 获取用户对应的ClientId
	 * @param userName
	 * @return
	 */
	@RequestMapping(value="/getClientId.aspx")
	public ModelAndView getClientId(HttpServletRequest request,
			HttpServletResponse response) {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return noticeService.getClientId(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}
	/**
	 * 开启活动开关接口
	 */
	@RequestMapping(value="/openActivity.aspx")
	public ModelAndView openActivity(HttpServletRequest request,
									 HttpServletResponse response) {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return noticeService.openActivity(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);

			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}
}
